package com.loukou.lkt.lkt.service.impl;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;

import org.apache.log4j.Logger;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;

import com.google.common.collect.Lists;
import com.loukou.lkt.lkt.bo.AllocationOrderBo;
import com.loukou.lkt.lkt.bo.PageList;
import com.loukou.lkt.lkt.bo.Query;
import com.loukou.lkt.lkt.constant.Urls;
import com.loukou.lkt.lkt.dao.AllocationOrderDao;
import com.loukou.lkt.lkt.dao.AllocationOrderDetailDao;
import com.loukou.lkt.lkt.dao.GoodsStockDao;
import com.loukou.lkt.lkt.dao.WarehouseDao;
import com.loukou.lkt.lkt.entity.AllocationOrder;
import com.loukou.lkt.lkt.entity.AllocationOrderDetail;
import com.loukou.lkt.lkt.entity.GoodsStock;
import com.loukou.lkt.lkt.entity.Warehouse;
import com.loukou.lkt.lkt.enums.AllocationOrderStateEnum;
import com.loukou.lkt.lkt.enums.GoodsStockStateEnum;
import com.loukou.lkt.lkt.enums.PositionTypeEnum;
import com.loukou.lkt.lkt.enums.StockInOrderTypeEnum;
import com.loukou.lkt.lkt.enums.StockOutOrderTypeEnum;
import com.loukou.lkt.lkt.req.AllocationStockRealDetailReq;
import com.loukou.lkt.lkt.req.AllocationStockRealReq;
import com.loukou.lkt.lkt.req.WhPurchaseOrderDto;
import com.loukou.lkt.lkt.req.WmsInOrderNoticeDetailReq;
import com.loukou.lkt.lkt.req.WmsInOrderNoticeReq;
import com.loukou.lkt.lkt.req.WmsOutOrderNoticeDetailReq;
import com.loukou.lkt.lkt.req.WmsOutOrderNoticeReq;
import com.loukou.lkt.lkt.resp.RespDto;
import com.loukou.lkt.lkt.service.AllocationOrderService;
import com.loukou.lkt.lkt.utils.PostUtils;

@Service
public class AllocationOrderServiceImpl implements AllocationOrderService{
	
	@Autowired
	private AllocationOrderDao allocationOrderDao;
	@Autowired
	private AllocationOrderDetailDao allocationOrderDetailDao;
	@Autowired
	private WarehouseDao warehouseDao;
	@Autowired
	private GoodsStockDao goodsStockDao;
	
	private Logger logger = Logger.getLogger(AllocationOrderServiceImpl.class);
	
	@Override
	public RespDto<PageList<AllocationOrderBo>> getAllocationOrderlst(
			final String orderCode,final int orderState, final int outWarehouseId,
			final int inWarehouseId,final List<Integer> myWarehouseIds, final String outUserName, final Date startCreateTime, final Date endCreateTime,
			final Date startOutTime, final Date endOutTime, final Date startInTime, final Date endInTime,int pageIndex,int pageSize) {
	
		RespDto<PageList<AllocationOrderBo>> resp = new RespDto<PageList<AllocationOrderBo>>();
		if(CollectionUtils.isEmpty(myWarehouseIds)){
			return resp;
		}
		Page<AllocationOrder> pageDtos = allocationOrderDao.findAll(new Specification<AllocationOrder>() {
			@Override
			public Predicate toPredicate(Root<AllocationOrder> root, CriteriaQuery<?> query, CriteriaBuilder cb) {
				Query<AllocationOrder> q = new Query<AllocationOrder>(cb, root, query);
				q.like("orderCode", orderCode);
				if(orderState>-1){
					q.eq("orderState", orderState);
				}
				if(outWarehouseId>-1){
					q.eq("outWarehouseId", outWarehouseId);
				}
				if(inWarehouseId>-1){
					q.eq("inWarehouseId", inWarehouseId);
				}
				if(outWarehouseId<0&&inWarehouseId<0){
					q.orIn("outWarehouseId","inWarehouseId", myWarehouseIds,myWarehouseIds);
				}
				q.like("outUserName", outUserName);
				q.betweens("createTime", startCreateTime, endCreateTime);
				q.betweens("outTime", startOutTime, endOutTime);
				q.betweens("inTime", startInTime, endInTime);
				return q.toPredicate();
			}
		}, new PageRequest(pageIndex - 1, pageSize,Sort.Direction.DESC, "createTime"));
		PageList<AllocationOrderBo> pageList = new PageList<AllocationOrderBo>();
		List<AllocationOrderBo> bolist = Lists.newArrayList();
		List<Integer> warehouseIds = Lists.newArrayList();
		for(AllocationOrder allocation:pageDtos.getContent()){
			if(!warehouseIds.contains(allocation.getOutWarehouseId())){
				warehouseIds.add(allocation.getOutWarehouseId());
			}
			if(!warehouseIds.contains(allocation.getInWarehouseId())){
				warehouseIds.add(allocation.getInWarehouseId());
			}
		}
		List<Warehouse> warehouses = Lists.newArrayList();
		if(!CollectionUtils.isEmpty(warehouseIds)){
			warehouses = warehouseDao.findByWarehouseStateAndWarehouseIdIn(1, warehouseIds);
		}
		Map<Integer,Warehouse> warehouseMap = new HashMap<Integer,Warehouse>();
		for(Warehouse warehouse:warehouses){
			warehouseMap.put(warehouse.getWarehouseId(), warehouse);
		}
		SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd");
		for(AllocationOrder allocation:pageDtos.getContent()){
			AllocationOrderBo allocationBo = new AllocationOrderBo();
			BeanUtils.copyProperties(allocation, allocationBo);
			if(allocation.getHopeOutTime() != null){
				allocationBo.setHopeOutTimeStr(sf.format(allocation.getHopeOutTime()));
			}
			if(allocation.getHopeInTime() != null){
				allocationBo.setHopeInTimeStr(sf.format(allocation.getHopeInTime()));
			}
			allocationBo.setOrderStateStr(AllocationOrderStateEnum.parseOrderStateEnum(allocation.getOrderState()).getName());
			Warehouse whout = warehouseMap.get(allocation.getOutWarehouseId());
			if(whout!=null){
				allocationBo.setOutWarehouseName(whout.getWarehouseName());
			}
			Warehouse whin = warehouseMap.get(allocation.getInWarehouseId());
			if(whin!=null){
				allocationBo.setInWarehouseName(whin.getWarehouseName());
			}
			bolist.add(allocationBo);
		}
		pageList.setEntityList(bolist);
		pageList.setCurPageIndex(pageIndex);
		pageList.setPageCount(pageDtos.getTotalPages());
		pageList.setRecordCount(pageDtos.getTotalElements());
		resp.setResult(pageList);
		return resp;
	}
	@Override
	public List<AllocationOrderDetail> getDetailsByOrderId(int orderId) {

		return allocationOrderDetailDao.findByOrderId(orderId);
	}
	
	@Override
	@Transactional
	public void saveAllocation(AllocationOrder allocation, List<AllocationOrderDetail> details,int outWarehouseIdOld) {

		allocationOrderDao.save(allocation);
		List<AllocationOrderDetail> savedetails = Lists.newArrayList();
		List<AllocationOrderDetail> detailOlds = allocationOrderDetailDao.findByOrderId(allocation.getId());
		Map<Integer,AllocationOrderDetail> newDetailsMap = new HashMap<Integer,AllocationOrderDetail>();
		Map<Integer,AllocationOrderDetail> oldDetailsMap = new HashMap<Integer,AllocationOrderDetail>();
		for(AllocationOrderDetail olddetail:detailOlds){
			oldDetailsMap.put(olddetail.getId(), olddetail);
		}
		for(AllocationOrderDetail newdetail:details){
			newDetailsMap.put(newdetail.getId(), newdetail);
		}
		//已有的
		for(AllocationOrderDetail detailOld:detailOlds){
			AllocationOrderDetail newDetail = newDetailsMap.get(detailOld.getId());
			//int stocktemp = 0;
			if(newDetail!=null){
				//修改
				newDetail.setId(detailOld.getId());
				newDetail.setOrderId(allocation.getId());
				savedetails.add(newDetail);
				//stocktemp = newDetail.getPlanQuantity() - detailOld.getPlanQuantity();
				//if(stocktemp !=0)updateAllocationStock(allocation.getOutWarehouseId(),detailOld.getOutGoodsSpecId(),GoodsStockStateEnum.STATE_AllocationStay.getId(),detailOld.getOutGoodsId(),stocktemp);
			}else{
				//删除
				//stocktemp = 0-detailOld.getPlanQuantity();
				allocationOrderDetailDao.delete(detailOld.getId());
				//if(stocktemp !=0)updateAllocationStock(outWarehouseIdOld,detailOld.getOutGoodsSpecId(),GoodsStockStateEnum.STATE_AllocationStay.getId(),detailOld.getOutGoodsId(),stocktemp);
			}
		}
		//新加的
		for(AllocationOrderDetail newdetail:details){
			AllocationOrderDetail oldDetail = oldDetailsMap.get(newdetail.getId());
			if(oldDetail ==null){
				newdetail.setOrderId(allocation.getId());
				savedetails.add(newdetail);
				//updateAllocationStock(allocation.getOutWarehouseId(),newdetail.getOutGoodsSpecId(),GoodsStockStateEnum.STATE_AllocationStay.getId(),newdetail.getOutGoodsId(),newdetail.getPlanQuantity());
			}
		}
		allocationOrderDetailDao.save(savedetails);
	}
	
	@Transactional
	private void updateAllocationStock(int warehouseId,int stockState,int goodsId,int stocknum){
		//增加待出库库存
		GoodsStock goodsstock = goodsStockDao.findByWarehouseIdAndPositionTypeAndGoodsIdAndStockState(warehouseId, PositionTypeEnum.TYPE_Normal.getId(), goodsId, stockState);
		if(goodsstock!=null){
			goodsStockDao.plusStock(warehouseId, PositionTypeEnum.TYPE_Normal.getId(), stockState, goodsId, stocknum);
		}else{
			GoodsStock stock = new GoodsStock();
			stock.setCreateTime(new Date());
			stock.setGoodsId(goodsId);
			stock.setPositionType(PositionTypeEnum.TYPE_Normal.getId());
			stock.setStockState(stockState);
			stock.setStock(stocknum);
			stock.setWarehouseId(warehouseId);
			goodsStockDao.save(stock);
		}
		if(stockState != GoodsStockStateEnum.STATE_Normal.getId()){
			//增加非正常库存，减少相应的正常库存
			goodsStockDao.minusStock(warehouseId, PositionTypeEnum.TYPE_Normal.getId(),  GoodsStockStateEnum.STATE_Normal.getId(), goodsId, stocknum);
		}
	}
	
	@Override
	public RespDto<String> sendAllocationOrderToWms(int allocationOrderId) {
		RespDto<String> resp = new RespDto<String>();
		WmsInOrderNoticeReq wmsInOrderNotice = new WmsInOrderNoticeReq();//LKT根据调拨单通知WMS入库
		WmsOutOrderNoticeReq wmsOutOrderNotice = new WmsOutOrderNoticeReq();//LKT根据调拨单通知WMS出库
		AllocationOrder allocationOrderDto = allocationOrderDao.findOne(allocationOrderId);
		if(allocationOrderDto == null){
			resp.setCode(401);
			resp.setResult(allocationOrderId + "未找到对应调拨单");
			return resp;
		}
		Warehouse inWarehouse = warehouseDao.findOne(allocationOrderDto.getInWarehouseId());
		if(inWarehouse == null){
			resp.setCode(402);
			resp.setResult("未找到对应入库仓库");
			return resp;
		}
		Warehouse outWarehouse = warehouseDao.findOne(allocationOrderDto.getOutWarehouseId());
		if(outWarehouse == null){
			resp.setCode(402);
			resp.setResult("未找到对应出库仓库");
			return resp;
		}
		wmsInOrderNotice.setOutbizCode(""+allocationOrderDto.getOrderCode());
		wmsInOrderNotice.setOrderType(StockOutOrderTypeEnum.TYPE_AllOCATION.getType());
//		wmsInOrderNotice.setOrderType(0);
		wmsInOrderNotice.setWarehouseNo(inWarehouse.getWarehouseCode());
		wmsInOrderNotice.setRemark(allocationOrderDto.getRemark());
		wmsOutOrderNotice.setOutbizCode(""+allocationOrderDto.getOrderCode());
		wmsOutOrderNotice.setWarehouseNo(outWarehouse.getWarehouseCode());
		wmsOutOrderNotice.setRemark(allocationOrderDto.getRemark());
		List<AllocationOrderDetail> allocationOrderDetailList = allocationOrderDetailDao.findByOrderId(allocationOrderId);
		if(allocationOrderDetailList == null || allocationOrderDetailList.size() == 0){
			resp.setCode(402);
			resp.setResult(allocationOrderId + "调拨单明细不存在");
			return resp;
		}
		List<WmsInOrderNoticeDetailReq> wmsInOrderNoticeDetailList = new ArrayList<WmsInOrderNoticeDetailReq>();
		List<WmsOutOrderNoticeDetailReq> wmsOutOrderNoticeDetailList = new ArrayList<WmsOutOrderNoticeDetailReq>();
		for(AllocationOrderDetail orderDetail : allocationOrderDetailList){
			WmsInOrderNoticeDetailReq inDetailReq = new WmsInOrderNoticeDetailReq();
			WmsOutOrderNoticeDetailReq outDetailReq = new WmsOutOrderNoticeDetailReq();
			inDetailReq.setOutbizId(""+orderDetail.getId());
			inDetailReq.setCustomerGoodsId(""+orderDetail.getInGoodsId());
			inDetailReq.setGoodsName(orderDetail.getInGoodsName());
			inDetailReq.setBarcode(orderDetail.getInGoodsBarcode());
			inDetailReq.setQuantity(orderDetail.getPlanQuantity());
			
			outDetailReq.setOutbizId(""+orderDetail.getId());
			outDetailReq.setCustomerGoodsId(""+orderDetail.getOutGoodsId());
			outDetailReq.setGoodsName(orderDetail.getOutGoodsName());
			outDetailReq.setBarcode(orderDetail.getOutGoodsBarcode());
			outDetailReq.setQuantity(orderDetail.getPlanQuantity());
			
			wmsInOrderNoticeDetailList.add(inDetailReq);
			wmsOutOrderNoticeDetailList.add(outDetailReq);
		}
		wmsInOrderNotice.setDetails(wmsInOrderNoticeDetailList);
		wmsOutOrderNotice.setDetails(wmsOutOrderNoticeDetailList);
		Map<String, String> wmsInOrder = (Map<String, String>) PostUtils.postData(Urls.LktTellWmsInOrderNotice, wmsInOrderNotice);
		if(wmsInOrder == null){
			resp.setCode(403);
			resp.setResult("通知WMS入库失败");
			return resp;
		}
		if(!"200".equals(wmsInOrder.get("code"))){
			resp.setCode(Integer.valueOf(wmsInOrder.get("code")));
			resp.setResult(wmsInOrder.get("success"));
			resp.setMsg(wmsInOrder.get("errorMsg"));
			return resp;
		}
		Map<String, String> wmsOutOrder = (Map<String, String>) PostUtils.postData(Urls.LktTellWmsOutOrderNotice, wmsOutOrderNotice);
		if(wmsOutOrder == null){
			resp.setCode(405);
			resp.setResult("通知WMS出库失败");
			return resp;
		}
		if(!"200".equals(wmsOutOrder.get("code"))){
			resp.setCode(Integer.valueOf(wmsOutOrder.get("code")));
			resp.setResult(wmsOutOrder.get("success"));
			resp.setMsg(wmsOutOrder.get("errorMsg"));
			return resp;
		}
		return resp;
	}
	
	@Override
	@Transactional
	public RespDto<String> wmsRealStockInOut(AllocationStockRealReq allocationStockReal) {
		RespDto<String> resp = new RespDto<String>();
		if(allocationStockReal == null || allocationStockReal.getOrderCode() == null || 
				allocationStockReal.getInOrOut() == null || allocationStockReal.getWmsOrderCode() == null){
			resp.setCode(401);
			resp.setMsg("参数错误");
			return resp;
		}
		List<AllocationStockRealDetailReq> stockRealList = allocationStockReal.getDetails();
		if(stockRealList == null){
			stockRealList = new ArrayList<AllocationStockRealDetailReq>();
		}
		if("in".equals(allocationStockReal.getInOrOut())){
			allocationOrderDao.updateInOrderCode(allocationStockReal.getOrderCode(), AllocationOrderStateEnum.TYPE_In.getId(), allocationStockReal.getWmsOrderCode(), allocationStockReal.getTime());
			for(AllocationStockRealDetailReq stockRealDetail : stockRealList){
				if(stockRealDetail.getRealQuantity() > 0){
					allocationOrderDetailDao.updateSendQuantity(stockRealDetail.getAllocationDetailId(), stockRealDetail.getRealQuantity());
				}
			}
		}else if("out".equals(allocationStockReal.getInOrOut())){
			allocationOrderDao.updateOutOrderCode(allocationStockReal.getOrderCode(),AllocationOrderStateEnum.TYPE_Out.getId(), allocationStockReal.getWmsOrderCode(), allocationStockReal.getTime());
			for(AllocationStockRealDetailReq stockRealDetail : stockRealList){
				if(stockRealDetail.getRealQuantity() > 0){
					allocationOrderDetailDao.updateReceiveQuantity(stockRealDetail.getAllocationDetailId(), stockRealDetail.getRealQuantity());
				}
			}
		}
		resp.setMsg("修改完成");
		return resp;
	}
	@Override
	public AllocationOrder getAllocationOrder(String orderCode) {
		return allocationOrderDao.findByOrderCode(orderCode);
	}
	@Override
	public AllocationOrder getAllocationOrderById(int id) {
		return allocationOrderDao.findOne(id);
	}
	
	@Override
	@Transactional
	public void updateState(int orderId, int state) {
		allocationOrderDao.updateState(orderId, state);
		
	}
	
	@Override
	@Transactional
	public RespDto<String> receiveWhPurchaseOrder(WhPurchaseOrderDto req) {
		return null;
	}
	@Override
	public void noticeWmsIn() {
		List<AllocationOrder> allocationOrderList = allocationOrderDao.findByOrderState(AllocationOrderStateEnum.TYPE_Out.getId());
		if(allocationOrderList == null || allocationOrderList.size() == 0){
			return;
		}
		for(AllocationOrder allocationOrderDto : allocationOrderList){
			logger.info("----------开始推送入库提醒:调拨单ID:"+allocationOrderDto.getId()+"------------");
			Warehouse warehouse = warehouseDao.findOne(allocationOrderDto.getInWarehouseId());
			List<AllocationOrderDetail> allocationOrderDetailList = allocationOrderDetailDao.findByOrderId(allocationOrderDto.getId());
			if(warehouse == null){
				logger.error(allocationOrderDto.getId() + "调拨单的出库仓库不存在！");
				continue;
			}
			if(allocationOrderDetailList == null || allocationOrderDetailList.size() == 0){
				logger.error(allocationOrderDto.getId() + "调拨明细不存在！");
				continue;
			}
			WmsInOrderNoticeReq wmsInOrderNotice = new WmsInOrderNoticeReq();//LKT根据调拨单通知WMS入库
			wmsInOrderNotice.setOutbizCode(""+allocationOrderDto.getOrderCode());
			wmsInOrderNotice.setOrderType(StockInOrderTypeEnum.TYPE_AllOCATION.getType());
			wmsInOrderNotice.setWarehouseNo(warehouse.getWarehouseCode());
			wmsInOrderNotice.setRemark(allocationOrderDto.getRemark());
			List<WmsInOrderNoticeDetailReq> wmsInOrderNoticeDetailList = new ArrayList<WmsInOrderNoticeDetailReq>();
			for(AllocationOrderDetail orderDetail : allocationOrderDetailList){
				WmsInOrderNoticeDetailReq inDetailReq = new WmsInOrderNoticeDetailReq();
				inDetailReq.setOutbizId(""+orderDetail.getId());
				inDetailReq.setCustomerGoodsId(""+orderDetail.getInGoodsId());
				inDetailReq.setGoodsName(orderDetail.getInGoodsName());
				inDetailReq.setBarcode(orderDetail.getInGoodsBarcode());
				inDetailReq.setQuantity(orderDetail.getPlanQuantity());
				wmsInOrderNoticeDetailList.add(inDetailReq);
			}
			wmsInOrderNotice.setDetails(wmsInOrderNoticeDetailList);
			Map<String, String> resp = (Map<String, String>) PostUtils.postData(Urls.LktTellWmsInOrderNotice, wmsInOrderNotice);
			if(resp == null){
				logger.error("推送入库返回信息为空");
			}else{
				if(!"200".equals(resp.get("code"))){
					logger.error("WMS返回信息:error:"+ resp.get("errorMsg"));
				}else{
					allocationOrderDto.setOrderState(AllocationOrderStateEnum.TYPE_NoticeIn.getId());
					allocationOrderDao.save(allocationOrderDto);
				}
			}
		}
	}
	@Override
	public void noticeWmsOut() {
		List<AllocationOrder> allocationOrderList = allocationOrderDao.findByOrderState(AllocationOrderStateEnum.TYPE_Checked.getId());
		if(allocationOrderList != null && allocationOrderList.size() > 0){
			for(AllocationOrder allocationOrderDto : allocationOrderList){
				logger.info("*******开始推送调拨出库提醒：调拨单ID："+allocationOrderDto.getId()+"**********");
				Warehouse outWarehouse = warehouseDao.findOne(allocationOrderDto.getOutWarehouseId());
				List<AllocationOrderDetail> allocationOrderDetailList = allocationOrderDetailDao.findByOrderId(allocationOrderDto.getId());
				if(outWarehouse == null){
					logger.error(allocationOrderDto.getId() + "调拨单的出库仓库不存在！");
					continue;
				}
				if(allocationOrderDetailList == null || allocationOrderDetailList.size() == 0){
					logger.error(allocationOrderDto.getId() + "调拨明细不存在！");
					continue;
				}
				WmsOutOrderNoticeReq wmsOutOrderNotice = new WmsOutOrderNoticeReq();
				wmsOutOrderNotice.setOutbizCode(""+allocationOrderDto.getOrderCode());
				wmsOutOrderNotice.setWarehouseNo(outWarehouse.getWarehouseCode());
				wmsOutOrderNotice.setOrderType(StockOutOrderTypeEnum.TYPE_AllOCATION.getType());
				wmsOutOrderNotice.setRemark(allocationOrderDto.getRemark());
				List<WmsOutOrderNoticeDetailReq> wmsOutOrderNoticeDetailList = new ArrayList<WmsOutOrderNoticeDetailReq>();
				for(AllocationOrderDetail orderDetail : allocationOrderDetailList){
					WmsOutOrderNoticeDetailReq outDetailReq = new WmsOutOrderNoticeDetailReq();
					outDetailReq.setOutbizId(""+orderDetail.getId());
					outDetailReq.setCustomerGoodsId(""+orderDetail.getOutGoodsId());
					outDetailReq.setGoodsName(orderDetail.getOutGoodsName());
					outDetailReq.setBarcode(orderDetail.getOutGoodsBarcode());
					outDetailReq.setQuantity(orderDetail.getPlanQuantity());
					wmsOutOrderNoticeDetailList.add(outDetailReq);
				}
				wmsOutOrderNotice.setDetails(wmsOutOrderNoticeDetailList);
				Map<String, String> wmsOutOrder = (Map<String, String>) PostUtils.postData(Urls.LktTellWmsOutOrderNotice, wmsOutOrderNotice);
				if(wmsOutOrder == null){
					logger.error("推送调拨出库没有返回信息");
				}else{
					if(!"200".equals(wmsOutOrder.get("code"))){
						logger.error("WMS返回信息:error:"+ wmsOutOrder.get("errorMsg"));
					}else{
						allocationOrderDto.setOrderState(AllocationOrderStateEnum.TYPE_NoticeOut.getId());
						allocationOrderDao.save(allocationOrderDto);
					}
				}
			}
		}
	}
	
	@Override
	public void checkAndUpdateState(int orderId, int outWarehouseId, List<AllocationOrderDetail> details) {
		allocationOrderDao.updateState(orderId, AllocationOrderStateEnum.TYPE_Checked.getId());
		//审核冻结
       for(AllocationOrderDetail newdetail:details){
		 updateAllocationStock(outWarehouseId,GoodsStockStateEnum.STATE_AllocationStay.getId(),newdetail.getOutGoodsId(),newdetail.getPlanQuantity());		
	   }
	}
	@Override
	public AllocationOrderDetail getDetail(int orderId, int outGoodsId) {
		// TODO Auto-generated method stub
		return allocationOrderDetailDao.findByOrderIdAndOutGoodsId(orderId, outGoodsId);
	}
}
